package com.ywm.eduOrder.service.impl;

import com.ywm.commonUtil.orderVo.CourseWebVoOrder;
import com.ywm.commonUtil.orderVo.UcenterMemberOrder;
import com.ywm.eduOrder.client.EduClient;
import com.ywm.eduOrder.client.UcenterClient;
import com.ywm.eduOrder.entity.TOrder;
import com.ywm.eduOrder.mapper.TOrderMapper;
import com.ywm.eduOrder.service.TOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ywm.eduOrder.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-06-06
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
    @Autowired(required=true)
    private EduClient eduClient;
    @Autowired(required=true)
    private UcenterClient centerClient;
    @Override
    public String createOrders(String courseId, String token) {
        //通过远程调用根据用户id获取用户信息
        CourseWebVoOrder courseInfoOrder = eduClient.getCourseInfoOrder(courseId);
        //通过远程调用根据课程id获取课程信息
        UcenterMemberOrder userInfoOrder = centerClient.getUserInfoById(token);
        TOrder order = new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfoOrder.getTitle());
        order.setCourseCover(courseInfoOrder.getCover());
        order.setTeacherName(courseInfoOrder.getTeacherName());
        order.setTotalFee(courseInfoOrder.getPrice());
        order.setMemberId(token);
        order.setMobile(userInfoOrder.getMobile());
        order.setNickname(userInfoOrder.getNickname());
        order.setStatus(0);//订单状态： 0  未支付；1  已支付
        order.setPayType(1);//支付类型： 1 微信
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
